{extend name='self@public/none'}

{block name="main"}
<style>
    body{
        height:90%;
    }
</style>
<form class="form mt-2">
    <div class="form-inline col-12   form-group" style="margin:0 auto">
        <label class="col-3" for="type">分类<span style="color:red"> *</span> </label>
        <select class="form-control col-8" id="type"  name="type" data-value="{$data['type']}"   autocomplete="off">
            <option value="" > --请选择-- </option>
            {foreach $selectData['type'] as $v}
            <option value="{$v['key']}">{$v['value']}</option>
            {/foreach}
        </select>
    </div>


    <div class="form-inline col-12   form-group" style="margin:0 auto">
        <label class="col-3" for="status">状态</label>
        <select class="form-control col-8" id="status" name="status" data-value="{$data['status']}" autocomplete="off">
            <option value="0" selected>正常</option>
            <option value="1">禁用</option>
        </select>
    </div>
    <div class="form-inline col-12  form-group" style="margin:0 auto">
        <label class="col-3" >图片</label>
        <div id="imgDiv">
            <input class="form-control col-9" id="img" value="{$data['img']}" name="img"     autocomplete="off">
        </div>
    </div>

    <div class="text-center mt-5">
        <button type="button" class="btn btn-info btn-cancel" id="close"> <i class="fa fa-close"></i> 取消</button>
        <button type="button" class="btn btn-info ml-2"  id="save"><i class="fa fa-floppy-o"></i> 保存</button>
    </div>
    <input type="hidden" value="{$Think.get.id}" id="id" name="id"/>
</form>

{/block}

{block name="script"}
<!--上传图片-->
<script>
    let width = $("#type").width();
    $("#imgDiv").width(width+22);
    $("#img").ptimg({accept:".jpg,.jpeg,.gif,.png"});
</script>
<!--数据-->
<script>
    $("#save").on('click',function()
    {
        let form = $("form").serializeObject();
        if(form.type == ''){
            layer.alert('分类不能为空,请选择');
            return;
        }


        frame.ajax({
            type:'post',
            url:'postData',
            data:{data:form}
        }).then(function(res)
        {
            handleRes(res,'children');
        })
    })

    $("#close").on('click',function()
    {
        layer.confirm("您确定要关闭当前页面吗?",function()
        {
            parent.layer.closeAll();
        })
    })
</script>
{/block}
